<?php
namespace App\Http\Controllers\Api\Repositories;

use App\Models\WxSyncRelation as Model;

class WxSyncRelationRepositories{
    protected $eloquentClass = Model::class;

    /** 获取内部id
     * @param $domain
     * @param $type
     * @param $id
     * @return mixed
     */
    public static function inner_id($domain, $type, $id){
        return Model::where([['domain', '=', $domain],['type', '=', $type],['external_id', '=', $id]])->value('inner_id');
    }

    /** 获取外部id
     * @param $domain
     * @param $type
     * @param $id
     * @return mixed
     */
    public static function external_id($domain, $type, $id){
        return Model::where([['domain', '=', $domain],['type', '=', $type],['inner_id', '=', $id]])->value('external_id');
    }
    /**
     * 根据inner_id获取外部external_id
     * @param $domain
     * @param $uid
     * @return mixed
     */
    public static function uid($domain, $uid){
        return Model::where([['domain', '=', $domain],['type', '=', 'user'],['inner_id', '=', $uid]])->value('external_id');
    }

    /**
     * 根据inner_id获取外部external_id
     * @param $domain
     * @param $post_id
     * @return mixed
     */
    public static function post_id($domain, $post_id){
        return Model::where([['domain', '=', $domain],['type', '=', 'post'],['inner_id', '=', $post_id]])->value('external_id');
    }

    /**
     * 获取外部评论id
     * @param $domain
     * @param $comment_id
     * @return mixed
     */
    public static function comment_id($domain, $comment_id){
        return Model::where([['domain', '=', $domain],['type', '=', 'comment'],['inner_id', '=', $comment_id]])->value('external_id');
    }

    /**
     * 根据inner_id获取外部external_id
     * @param $domain
     * @param $good_id
     * @return mixed
     */
    public static function good_id($domain, $good_id){
        return Model::where([['domain', '=', $domain],['type', '=', 'good'],['inner_id', '=', $good_id]])->value('external_id');
    }

    /**
     * 根据外部id获取内部id
     * @param $domain
     * @param $uid
     * @return mixed
     */
    public static function wx_uid( $domain, $uid ){
        return Model::where([['domain', '=', $domain],['type', '=', 'user'],['external_id', '=', $uid]])->value('inner_id');
    }

    /**
     * 根据外部id获取内部id
     * @param $domain
     * @param $post_id
     * @return mixed
     */
    public static function wx_post_id($domain, $post_id){
        return Model::where([['domain', '=', $domain],['type', '=', 'post'],['external_id', '=', $post_id]])->value('inner_id');
    }

    public static function wx_good_id($domain, $good_id){
        return Model::where([['domain', '=', $domain],['type', '=', 'good'],['external_id', '=', $good_id]])->value('inner_id');
    }

    public static function wx_comment_id($domain, $comment_id){
        return Model::where([['domain', '=', $domain],['type', '=', 'comment'],['external_id', '=', $comment_id]])->value('inner_id');
    }

}
